import { Injectable } from '@nestjs/common'
import { Model } from 'mongoose'
import { InjectModel } from '@nestjs/mongoose'
import { WorkflowData } from './schemas/workflowData.schema'

@Injectable()
export class WorkflowDataService {
  constructor(
    @InjectModel(WorkflowData.name)
    private workflowDataModel: Model<WorkflowData>
  ) {}

  async insertMany(data: any[]): Promise<any[]> {
    return this.workflowDataModel.insertMany(data)
  }

  async find(data: any): Promise<any[]> {
    return this.workflowDataModel.find(data).exec()
  }

  async findOne(data: any) {
    return this.workflowDataModel.findOne(data).exec()
  }

  async updateOne(data: any) {
    const _id = data._id
    Reflect.deleteProperty(data, '_id')
    return this.workflowDataModel.updateOne({ _id }, { $set: data }).exec()
  }

  async deleteOne(data: any) {
    return await this.workflowDataModel.deleteOne(data).exec()
  }
}
